using System.Collections;
using UnityEngine;

public class BattleAttack_Siplett_Kaplunk : MonoBehaviour
{
	public SpriteRenderer LiquidFront_Renderer;

	public SpriteRenderer LiquidBack_Renderer;

	[SerializeField]
	private float AttackTime;

	[Space(10f)]
	[SerializeField]
	private float IceCubeSpawn_Y;

	[SerializeField]
	private float IceCubeSpawnRange_X;

	[SerializeField]
	private int IceCubesToSpawn = 15;

	[SerializeField]
	private GameObject IceCubePrefab;

	public static BattleAttack_Siplett_Kaplunk instance;

	private int spawnedIcecubes;

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		if ((Object)(object)LiquidFront_Renderer != (Object)null)
		{
			CutsceneUtils.FadeInSprite(LiquidFront_Renderer);
		}
		if ((Object)(object)LiquidBack_Renderer != (Object)null)
		{
			CutsceneUtils.FadeInSprite(LiquidBack_Renderer);
		}
		((MonoBehaviour)this).StartCoroutine(AttackLoop());
	}

	private IEnumerator AttackLoop()
	{
		if (spawnedIcecubes < IceCubesToSpawn)
		{
			spawnedIcecubes++;
			yield return (object)new WaitForSeconds(AttackTime / (float)(IceCubesToSpawn / 2));
			GameObject obj = Object.Instantiate<GameObject>(IceCubePrefab, BattleSystem.Instance.Holder_Bullets.transform);
			float num = Mathf.Clamp(((Component)Battle_PlayerSoul.Instance).transform.position.x + Random.Range(0f - IceCubeSpawnRange_X, IceCubeSpawnRange_X), ((Component)this).transform.position.x + -1.35f, ((Component)this).transform.position.x + 1.35f);
			obj.transform.parent = BattleSystem.Instance.Holder_Bullets.transform;
			obj.transform.position = Vector2.op_Implicit(new Vector2(num, ((Component)this).transform.position.y + IceCubeSpawn_Y));
			((MonoBehaviour)this).StartCoroutine(AttackLoop());
		}
	}
}
